import {_decorator, Component, Node, WebView, Label, EditBox} from 'cc';

const {ccclass, property} = _decorator;

@ccclass('WebViewScript')
export class WebViewScript extends Component {
    @property(WebView)
    webView: WebView

    @property(EditBox)
    inputUrl!: EditBox

    @property(Label)
    labelStatus !: Label;


    start() {
    }

    onWebFinishLoad(sender: any, event: any) {
        let loadStatus = "";
        if (event === WebView.EventType.LOADED) {
            loadStatus = " is loaded!";
        } else if (event === WebView.EventType.LOADING) {
            loadStatus = " is loading!";
        } else if (event === WebView.EventType.ERROR) {
            loadStatus = ' load error!';
        }
        this.labelStatus.string = this.webView.url + loadStatus;
    }

    update(deltaTime: number) {

    }

    searchButton() {
        this.webView.url = this.inputUrl.string
    }
}


